<?php
/**
 * Created by PhpStorm.
 * User: 84071
 * Date: 2018-03-02
 * Time: 9:02
 */
namespace app\common\model;
use think\Model;
class UserSpread extends Model{
    // 开启自动写入时间戳
    protected $autoWriteTimestamp = true;
    protected $insert = ['addtime','addip'];
    protected $type = [
        'addtime'    => 'timestamp',
    ];
    // 定义时间戳字段名
    protected $createTime = 'addtime';
    protected $updateTime = false;
    protected function setAddipAttr(){
        return request()->ip();
    }
    //  添加推荐信息
    public function newadd($uid,$puid){
        $old = $this->where('uid',$puid)->find();
        $euid = null;
        if(!empty($old['puid'])){
            $euid = $old['puid'];
        }
        $add = array(
            'uid' => $uid,
            'puid' => $puid,
            'euid' => $euid,
        );
        if($this->setAttr('id',null)->isUpdate(false)->save($add)){
            //  发送站内信息
            \model('Sms')->add_tui($add);
            //  更改用户积分
            // 瑜伽专用判断
            $pugroup_id = \model('UserData')->where('uid',$puid)->value('group_id');
            if($pugroup_id == '6'){
                return true;
            }
            \model('UserMoney')->add_tui($add);
            return true;
        }
        return false;
    }


}